;+
; NAME:
;       FDATA_VARIANCE_BGPS
;
; PURPOSE:
;       Calculate the variance (propagation of error) in the measured
;       foreground fraction (8-micron emission) based on uncertainties
;       in the input quantities.
;
; CATEGORY:
;       IRDC modeling
;
; CALLING SEQUENCE:
;       sig_f2 = FDATA_VARIANCE_BGPS( tau, Gamma, del_Imir, Imir, Imin
;                                [,/PRINT][,DELI_DEC = delI_dec])
;
; INPUTS:
;       TAU      -- The estimated 8-micron optical depth
;       GAMMA    -- The conversion factor from 1.2mm dust continuum
;                   emission to 8-micron optical depth (see
;                   GAMMA_INVERSE_MJY.pro)
;       DEL_IMIR -- The variation in the total MIR emission around an
;                   IRDC (from the PF09 catalog)
;       IMIR     -- The total MIR emission around an IRDC (from the
;                   PF09 catalog)  [MJy/sr]
;       IMIN     -- The minimum 8-micron intensity within an IRDC (or
;                   at the location of a mm-wave core)  [MJy/sr]
;
; OPTIONAL INPUTS:
;       DELI_DEC -- The factor by which to decrement the del_I from
;                   the Peretto & Fuller (2009) catalog.  This factor
;                   is present to investigate overestimation of the
;                   fdata_variance.
;
; KEYWORD PARAMETERS:
;       PRINT    -- Print debugging information.
;
; OUTPUTS:
;       The variance of f_data (foreground fraction of 8-micron
;       emission, as calculated from GLIMPSE and IRAM 30m data).  Take
;       sqrt() to get the uncertainty in f_data.
;
; OPTIONAL OUTPUTS:
;       NONE
;
; MODIFICATION HISTORY:
;
;       Created:  03/08/11, TPEB -- Initial codified version.
;       Modified: 04/18/11, TPEB -- Redid the method of calculation to
;                                   ensure no screw-ups.
;       Modified: 05/01/11, TPEB -- Added investigation-related input
;                                   DELI_DEC: the factor by which to
;                                   decrement the del_I from PF09.
;       Modified: 07/22/11, TPEB -- New routine for BGPS values.
;       Modified: 12/09/11, TPEB -- Updated create_bgps_rb3.struct.pro
;                                   to calculate the value of I_min,
;                                   I_MIR, C_MEAS, and all their
;                                   uncertainties, which are placed in
;                                   the rb3 structure.  So, accept
;                                   delivery of said varaibles.
;
;-

FUNCTION FDATA_VARIANCE_BGPS, tau, Gamma, C, sig_C, sig_s, PRINT=print
  
  ;; Calculate away!
  oneover2 = 1.d / ( (1.d - exp(-tau)) * (1.d - exp(-tau)) )
  
  RETURN,oneover2 * ( sig_C*sig_C + $
                      oneover2*(exp(-2.d*tau)*C*C*sig_s*sig_s*Gamma*Gamma) ) 
  
END
